//
//  AddStudentViewController.m
//  08_Homework
//
//  Created by 徐昊 on 16/7/25.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "AddStudentViewController.h"

@interface AddStudentViewController ()

@end

@implementation AddStudentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self config];
    _name = [[UITextField alloc] initWithFrame:CGRectMake(180, 100, 80, 50)];
    _name.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_name];
    _age = [[UITextField alloc] initWithFrame:CGRectMake(180, 200, 80, 50)];
    _age.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_age];
    _gender = [[UITextField alloc] initWithFrame:CGRectMake(180, 300, 80, 50)];
    _gender.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_gender];
    _phoneNumber = [[UITextField alloc] initWithFrame:CGRectMake(180, 400, 120, 50)];
    _phoneNumber.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_phoneNumber];
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(handleUp:)];
    self.navigationItem.rightBarButtonItem = button;

}
#pragma mark - 在某个时机让 代理人触发 协议方法
- (void)handleUp:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(addStudent:)]) {
        self.diction = [NSMutableDictionary dictionaryWithObjectsAndKeys:_name.text, @"name", _age.text, @"age", _gender.text, @"gender", _phoneNumber.text, @"phoneNumber", nil];
        [self.delegate addStudent:_diction];
    }

    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)config {
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 80, 50)];
    nameLabel.text = @"姓名";
    nameLabel.backgroundColor = [UIColor redColor];
    [self.view addSubview:nameLabel];
    nameLabel.textAlignment = NSTextAlignmentCenter;
    UILabel *ageLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 80, 50)];
    ageLabel.text = @"年龄";
    ageLabel.backgroundColor = [UIColor redColor];
    ageLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:ageLabel];
    UILabel *genderLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 300, 80, 50)];
    genderLabel.text = @"性别";
    genderLabel.backgroundColor = [UIColor redColor];
    [self.view addSubview:genderLabel];
    genderLabel.textAlignment = NSTextAlignmentCenter;
    UILabel *phoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 400, 80, 50)];
    phoneNumberLabel.text = @"电话号码";
    phoneNumberLabel.backgroundColor = [UIColor redColor];
    [self.view addSubview:phoneNumberLabel];
    phoneNumberLabel.textAlignment = NSTextAlignmentCenter;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
